package com.dingding.core.tailwind.dao.impl;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.UserLogin;
import com.dingding.core.tailwind.dao.ITailwindUserInfoDao;
import com.dingding.core.tailwind.sql.TailwindUserInfoSQL;

/**
 * 
 * @ClassName: TailwindUserInfoDaoImpl 
 * @Description: 顺风车用户信息DAO接口实现类
 * @author YHQ
 * @date 2016年12月27日 下午8:10:22
 * @since V2.6.3
 * 
 */
@Component("tailwindUserInfoDao")
public class TailwindUserInfoDaoImpl implements ITailwindUserInfoDao{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	/**
	 * 
	 * @Title: getUserLogin 
	 * @Description: 根据用户Id获取用户登录信息
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.6.3
	 * @return UserLogin    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public UserLogin getUserLogin(String userId) {
		
		try {
			return baseDaoX.getById(userId, UserLogin.class);
		} catch (Exception e) {
			log.error("根据用户Id获取用户登录信息时出现异常   类：" + this.getClass() + " getUserLogin()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: updateUserLogin 
	 * @Description: 修改用户登录信息
	 * @param userLogin 用户登录信息
	 * @author YHQ 
	 * @since V2.6.3
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean updateUserLogin(UserLogin userLogin) {
		
		try {
			baseDaoX.update(userLogin);
			return true;
		} catch (Exception e) {
			log.error("修改用户登录信息时出现异常   类：" + this.getClass() + " updateUserLogin()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: resetTailwindDepositNumber 
	 * @Description: 重置顺风车提现次数
	 * @author YHQ 
	 * @since V2.6.3
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean resetTailwindDepositNumber() {
		
		try {
			sqlBaseDao.updateSqLRow(TailwindUserInfoSQL.RESET_TAILWIND_DEPOSIT_NUMBER);
			return true;
		} catch (Exception e) {
			log.error("重置顺风车提现次数时出现异常   类：" + this.getClass() + " resetTailwindDepositNumber()", e);
		}
		
		return false;
	}
	
}
